package com.kcyu.sfhinvoice.utils;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.google.errorprone.annotations.Var;

import java.io.File;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LuckyColaUtils {

    public String getInvoiceDate(String fileUrl) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("ColaKey", "KC87rkn0chX4wn1709099615455N5O6op0lEM");
        map.put("file", new File(fileUrl));
        String post = HttpUtil.post("https://luckycola.com.cn/aiTools/imgOcr", map);
        post = post.replaceAll(" ", "");
        // 寻找开票日期
        System.out.println(post);
        Pattern pattern = Pattern.compile("开票日期:(.*?)\\\\n");
        Matcher matcher = pattern.matcher(post);
        if(matcher.find()){
            return matcher.group(1);
        } else {
            return null;
        }
    }
}
